package com.top4create.model;

import com.top4create.model.BaseObject;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableComponent;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import java.io.Serializable;

@Entity
@Table(name = "company", catalog = "top4create_test")
@Searchable
@XmlRootElement
public class Company extends BaseObject implements Serializable {
	private Long id;
	private Type2 type2;
	private Type type;

	private Type3 type3;
	private String discription;
	private String email;
	private String fax;
	private String location;
	private String name;
	private String phone;
	private String productionTag;
	private String site;
	private Long userId;
	private Set<FavourateCompany> favourateCompanies = new HashSet<FavourateCompany>(
			0);

	private Set<Connecter> connecters = new HashSet<Connecter>(0);
	private Set<SellInfo> sellInfos = new HashSet<SellInfo>(0);

	private Set<Position> positions = new HashSet<Position>(0);
	private Set<Pictorial> pictorials = new HashSet<Pictorial>(0);

	private Set<BuyInfo> buyInfos = new HashSet<BuyInfo>(0);

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@SearchableId
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@XmlTransient
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "type_scd_id")
	public Type2 getType2() {
		return this.type2;
	}

	public void setType2(Type2 type2) {
		this.type2 = type2;
	}

	@XmlTransient
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "type_id")
	public Type getType() {
		return this.type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	@XmlTransient
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "type_trd_id")
	public Type3 getType3() {
		return this.type3;
	}

	public void setType3(Type3 type3) {
		this.type3 = type3;
	}

	@Column(name = "discription", length = 300)
	@SearchableProperty
	public String getDiscription() {
		return this.discription;
	}

	public void setDiscription(String discription) {
		this.discription = discription;
	}

	@Column(name = "email", length = 30)
	@SearchableProperty
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "fax", length = 20)
	@SearchableProperty
	public String getFax() {
		return this.fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	@Column(name = "location", length = 60)
	@SearchableProperty
	public String getLocation() {
		return this.location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	@Column(name = "name", length = 60)
	@SearchableProperty
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "phone", length = 40)
	@SearchableProperty
	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "production_tag", length = 100)
	@SearchableProperty
	public String getProductionTag() {
		return this.productionTag;
	}

	public void setProductionTag(String productionTag) {
		this.productionTag = productionTag;
	}

	@Column(name = "site", length = 30)
	@SearchableProperty
	public String getSite() {
		return this.site;
	}

	public void setSite(String site) {
		this.site = site;
	}

	@Column(name = "user_id")
	@SearchableProperty
	public Long getUserId() {
		return this.userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	@XmlTransient
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "company")
	public Set<FavourateCompany> getFavourateCompanies() {
		return this.favourateCompanies;
	}

	public void setFavourateCompanies(Set<FavourateCompany> favourateCompanies) {
		this.favourateCompanies = favourateCompanies;
	}

	@XmlTransient
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "company")
	public Set<Connecter> getConnecters() {
		return this.connecters;
	}

	public void setConnecters(Set<Connecter> connecters) {
		this.connecters = connecters;
	}

	@XmlTransient
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "company")
	public Set<SellInfo> getSellInfos() {
		return this.sellInfos;
	}

	public void setSellInfos(Set<SellInfo> sellInfos) {
		this.sellInfos = sellInfos;
	}

	@XmlTransient
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "company")
	public Set<Position> getPositions() {
		return this.positions;
	}

	public void setPositions(Set<Position> positions) {
		this.positions = positions;
	}

	@XmlTransient
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "company")
	public Set<Pictorial> getPictorials() {
		return this.pictorials;
	}

	public void setPictorials(Set<Pictorial> pictorials) {
		this.pictorials = pictorials;
	}

	@XmlTransient
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "company")
	public Set<BuyInfo> getBuyInfos() {
		return this.buyInfos;
	}

	public void setBuyInfos(Set<BuyInfo> buyInfos) {
		this.buyInfos = buyInfos;
	}

	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Company pojo = (Company) o;

		if (type2 != null ? !type2.equals(pojo.type2) : pojo.type2 != null)
			return false;
		if (type != null ? !type.equals(pojo.type) : pojo.type != null)
			return false;
		if (type3 != null ? !type3.equals(pojo.type3) : pojo.type3 != null)
			return false;
		if (discription != null ? !discription.equals(pojo.discription)
				: pojo.discription != null)
			return false;
		if (email != null ? !email.equals(pojo.email) : pojo.email != null)
			return false;
		if (fax != null ? !fax.equals(pojo.fax) : pojo.fax != null)
			return false;
		if (location != null ? !location.equals(pojo.location)
				: pojo.location != null)
			return false;
		if (name != null ? !name.equals(pojo.name) : pojo.name != null)
			return false;
		if (phone != null ? !phone.equals(pojo.phone) : pojo.phone != null)
			return false;
		if (productionTag != null ? !productionTag.equals(pojo.productionTag)
				: pojo.productionTag != null)
			return false;
		if (site != null ? !site.equals(pojo.site) : pojo.site != null)
			return false;
		if (userId != null ? !userId.equals(pojo.userId) : pojo.userId != null)
			return false;

		return true;
	}

	public int hashCode() {
		int result = 0;
		result = (type2 != null ? type2.hashCode() : 0);
		result = 31 * result + (type != null ? type.hashCode() : 0);
		result = 31 * result + (type3 != null ? type3.hashCode() : 0);
		result = 31 * result
				+ (discription != null ? discription.hashCode() : 0);
		result = 31 * result + (email != null ? email.hashCode() : 0);
		result = 31 * result + (fax != null ? fax.hashCode() : 0);
		result = 31 * result + (location != null ? location.hashCode() : 0);
		result = 31 * result + (name != null ? name.hashCode() : 0);
		result = 31 * result + (phone != null ? phone.hashCode() : 0);
		result = 31 * result
				+ (productionTag != null ? productionTag.hashCode() : 0);
		result = 31 * result + (site != null ? site.hashCode() : 0);
		result = 31 * result + (userId != null ? userId.hashCode() : 0);

		return result;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer(getClass().getSimpleName());

		sb.append(" [");
		sb.append("id").append("='").append(getId()).append("', ");
		sb.append("type2").append("='").append(getType2()).append("', ");
		sb.append("type").append("='").append(getType()).append("', ");
		sb.append("type3").append("='").append(getType3()).append("', ");
		sb.append("discription").append("='").append(getDiscription())
				.append("', ");
		sb.append("email").append("='").append(getEmail()).append("', ");
		sb.append("fax").append("='").append(getFax()).append("', ");
		sb.append("location").append("='").append(getLocation()).append("', ");
		sb.append("name").append("='").append(getName()).append("', ");
		sb.append("phone").append("='").append(getPhone()).append("', ");
		sb.append("productionTag").append("='").append(getProductionTag())
				.append("', ");
		sb.append("site").append("='").append(getSite()).append("', ");
		sb.append("userId").append("='").append(getUserId()).append("', ");

		sb.append("]");

		return sb.toString();
	}

}
